<?php

/*
    picopress - A lightweighed online publishing system
    Copyright (C) 2010  Martin Burkert <martin@burkert.de>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
*/

class PicoSymbolsParser extends CoreParser implements Parser {

    public function parse ($content) {
    
        $content = str_replace('#node:', create_link(''), $content);
        $content = str_replace('#file:', BASE_URL.'/'.FILES_DIR.'/', $content);
        
        $template = $this->get_template();
        preg_match_all('/\{\$([A-Za-z0-9_]{1,32})\}/', $content, $matches);        
        foreach ($matches[1] as $match) {
            $content = str_replace('{$'.$match.'}', $template->get_var($match), $content);
        }

        preg_match_all('/\{\@([A-Za-z0-9_]{1,32})\}/', $content, $matches);        
        foreach ($matches[1] as $match) {
            $arr_var = $template->get_var($match);

            $content = str_replace('{@'.$match.'}', $this->make_html_list($template->get_var($match),$match), $content);
        }
        
        return $content;
    
    }
    
    public function make_html_list ($arr, $class) {
        $r = '';
        if(is_array($arr)){
            $r = "<ul class=\"$id\">";
            foreach($arr as $a){
                $r .= "<li>$a</li>";
            }
            $r .= '</ul>';
        }
        return $r;
    }    
    

}


?>